<template>
  <div>

    <el-row class="bread-nav">
      <ul class="bread-nav-title">
        <span>历史开奖结果</span>
      </ul>
      <ul class="bread-nav-right">
        <span>彩种: </span>
        <select v-if="game" v-model="game" @change="GetResult('')">
          <option v-for="(item,index) in gameOption" :value="item.value" :key="index">
            {{item.label}}
          </option>
        </select>
        <span>日期: </span>
        <div class="block">
          <label>
            <input type="text" v-model="date" id="datepicker">
          </label>
        </div>
      </ul>
    </el-row>

    <div>
      <table class="myTable">
        <thead>
        <tr>
          <th v-for="(item,index) in resultTitle" :key="index">
            {{item}}
          </th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(list,index) in gameResult" :key="index" class="myTableTr">
          <td v-for="(value, key, index) in list" :key="index" :class="{lineHeight:Array.isArray(value)}">
            <span v-if="!(value instanceof  Array)" :class="{colorred:value=='龙',colorredc:value=='和'}" class="JiangSpan">{{value}}</span>

            <div class="menu1 flexSpan" v-if="(value instanceof  Array)">
              <ul class="flexSpan" :class="{
                T_PK10:game ==='bjpk10'||game ==='azlucky10'||game ==='amsc'||game ==='jsft'||game ==='amjssc'||game ==='xyft'||game ==='jssc'||
                game ==='amjsssc'||game ==='amssc'||game ==='hlsc'||game ==='hljssc',
                T_KL8:game ==='bjkl8' || game ==='azlucky20',
                T_SSC:game ==='azlucky5'||game ==='jsssc'||game ==='xjssc'|| game ==='tjssc'||game ==='bsssc'||game ==='gama'||game === 'hlssc' || game ==='amssc'|| game ==='amjsssc',
                L_CQHLSX:game ==='cqssc',
                T_KLSF:game ==='gdklsf'|| game ==='azlucky8',
                XYNCTerm:game ==='cqxync',
                T_K3:game==='gxk3',
                T_11X5:game==='gd115',
                T_GXKLSF:game==='gxklsf',
                }" v-if="key === '开出号码' || key === '开出骰子'">
                  <div v-if="game==='pcegg'">
                    <div v-for="(item,index) in value" :key="index" class="spanBBS">
                      <span :class="'pc28_ball_'+ item"></span>
                    </div>
                  </div>
                  <div v-else>
                     <span class="spanBBS" :class="{otherSpan:game === 'cqxync'}" v-for="(item,index) in value" :key="index">
                  <b class="bb" :class="`b${item}`"></b>
                    </span>
                  </div>
                </ul>
                <span class="spanas"
                      :class="{colorredgxk3lv:iteml=='虾'||iteml=='螃蟹' ,colorredgxk3ls:iteml=='葫芦'||iteml=='金钱',colorredgxk3red:iteml=='鱼'||iteml=='鷄'}"
                      v-if="key==='鱼虾蟹'" v-for="(iteml,indexl) in value" :key="indexl">{{iteml}}
              </span>
              <span class="spanas"
                    :class="{colorred:iteml=='龙',colorreda:iteml=='大',colorredb:iteml=='双',otherSpan:game === 'cqxync', mulWordSpan:game ==='bjkl8' || game ==='azlucky20'}"
                    v-if="!(key === '开出号码' || key === '开出骰子' || key==='鱼虾蟹')" v-for="(iteml,indexl) in value" :key="indexl">{{iteml}}
              </span>
            </div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import $ from 'jquery'
  import 'jquery-ui/ui/widgets/datepicker'

  export default {
    name: 'notice',
    methods: {
      // 转换时间格式
      CurentTime(value) {
        const now = new Date(value)
        const year = now.getFullYear()
        const month = now.getMonth() + 1
        const day = now.getDate()
        let clock = year + '-'
        if (month < 10) {
          clock += '0'
        }
        clock += month + '-'
        if (day < 10) {
          clock += '0'
        }
        clock += day
        return (clock)
      },

      GetResult(date) {
        let theDate = ''
        this.gameResult = ''
        this.resultTitle = ''
        if (date === undefined || date === null || date === '') {
          theDate = this.date
        } else {
          theDate = date
        }
        const params = {
          game: this.game,
          date: theDate.replace(/-/g, ''),
        }
        this.$store.dispatch('GetResult', params)
          .then(response => {
            this.gameResult = JSON.parse(JSON.stringify(response.data1))
            this.resultTitle = JSON.parse(JSON.stringify(response.title1))
            console.log(this.gameResult)
            console.log(this.resultTitle)
          })
      },

      // 获取全部
      GetGameOptions() {
        this.gameOption = []
        this.$store.dispatch('GetGameOptions')
          .then(response => {
            for (const key in response) {
              if (key !== 'message') {
                for (const index in response[key]) {
                  const temp = {
                    label: response[key][index],
                    value: index,
                  }
                  this.gameOption.push(temp)
                }
              }
            }
            this.game = this.gameOption[0].value
            this.GetResult()
          })
      },
    },
    mounted() {
      const _this = this
      $(function() {
        $('#datepicker').datepicker({
          showMonthAfterYear: true,
          prevText: '上个月',
          nextText: '下个月',
          dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
          dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
          dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
          monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
            '七月', '八月', '九月', '十月', '十一月', '十二月'],
          dateFormat: 'yy-mm-dd',
          firstDay: 1,
          onSelect: function(date) {
            _this.date = date
            _this.GetResult(date)
          },
        })
      })
    },
    data() {
      return {
        date: '', // 日期
        game: '', // 彩种
        gameOption: [],
        gameResult: '', // 开奖结果
        resultTitle: '', // 开奖结果标题
      }
    },
    created() {
      const start = new Date()
      if (start.getHours() < 6) {
        start.setTime(start.getTime() - 3600 * 1000 * 24)
        this.date = this.CurentTime(start)
        this.GetGameOptions()
      } else {
        this.date = this.CurentTime(start)
        this.GetGameOptions()
      }
      // const nowTime = new Date()
      // this.date = this.CurentTime(nowTime)
      // this.GetGameOptions()
    },
    computed: { ...mapGetters(['info']) },
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .bread-nav{
    min-height:40px;
    font-size: 13px;
    line-height: 40px;
    background: #ECEFF2;
    border-bottom: 1px solid #d0dff2;
    padding: 0 0 0 10px;
    overflow: hidden;
  }
  .bread-nav-title{
    color:#386399;
    font-weight: bold;
    float: left;
    background: url("../../../../static/agent/img/tb.png") no-repeat left center;
    padding-left: 20px;
  }
  .bread-nav-right{
    float: right;
  }
  .block{
    float: right;
    height:40px;
  }


  .myTable{
    width: auto;
    margin: 2px auto;
    border-collapse: collapse;
    border-spacing: 0;
  }
  .myTable th{
    background: url(/static/agent/img/table_head.gif) repeat-x;
    height: 25px;
    text-align: center;
    color: #131950;
    font-weight: bold;
    line-height: 25px;
    font-size:14px;
    padding-left: 10px;
    padding-right: 10px;
    border: 1px solid #B9C2CB;
    margin: 0;
  }
  .myTable td{
    text-align: center;
    color: #131950;
    line-height: 32px;
    font-size:13px;
    /*padding: 5px;*/
    border: 1px solid #B9C2CB;
    box-sizing: border-box;
    padding: 0;
  }
  .myTableTr:hover{
    background-color: #deedfe;
  }

  .flexSpan{
    display: flex;
    justify-content: center;
  }
  .spanBBS{
    display: inline-block;
    border-right: 1px solid #B9C2CB;
    width: 32px;
    height:32px;
    line-height: 30px;
    vertical-align: middle;
    padding: 5px 0;
  }
  .T_PK10 .spanBBS{
    width: 23px !important;
    height:32px !important;
  }
  .otherSpan{
    width: 36px !important;
    height:36px !important;
  }
  .mulWordSpan{
    width: 50px !important;
  }

  .spanBBS:last-child{
    border:none !important;
  }
  .lineHeight{
    /*line-height: 0 !important;*/
  }
  .spanas{
    border-right: 1px solid #B9C2CB;
    width: 32px;
    height:32px;
  }
  .spanas:last-child{
    border-right:none;
  }
  .colorred{
    color: red;
  }
  .colorreda{
    color: red;
  }
  .colorredb{
    color: red;
  }
  .colorredc{
    color: #2836f4;
  }
  .colorredgxk3lv{
    color: rgb(34, 189, 30);
  }
  .colorredgxk3ls{
    color: rgb(40, 54, 244);
  }
  .colorredgxk3red{
    color: red;
  }

  .JiangSpan{
    padding:0 5px;
  }
</style>
